package com.xiangban.yanglaodajie_admin.controller;

import com.xiangban.yanglaodajie_admin.aop.Permission;
import com.xiangban.yanglaodajie_admin.entity.Goods;
import com.xiangban.yanglaodajie_admin.entity.dto.GoodsDto;
import com.xiangban.yanglaodajie_admin.entity.res.ApiResult;
import com.xiangban.yanglaodajie_admin.service.GoodsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author Mr. MaYaYun
 * @Data 2021/6/4 14:56
 */
@RestController
@RequestMapping("/api/admin/goods")
@Api(tags = "商品管理")
public class GoodsController {

    @Autowired
    private GoodsService goodsService;

    @PostMapping("/addOrUpdateGoods")
    @ApiOperation("添加或修改商品")
    @Permission(permission = "admin:goods:addOrUpdateGoods")
    public ApiResult<Object> addOrUpdateGoods(@RequestBody Goods goods){
        goodsService.addOrUpdateGoods(goods);
        return ApiResult.newSuccess();
    }

    @PostMapping("/alterGoods")
    @ApiOperation("删除或修改商品状态")
    @Permission(permission = "admin:goods:alterGoods")
    public ApiResult<Object> alterGoods(@RequestBody GoodsDto goodsDto){
        goodsService.delGoods(goodsDto);
        return ApiResult.newSuccess();
    }

    @PostMapping("/getGoodsList")
    @ApiOperation("商品列表")
    @Permission(permission = "admin:goods:getGoodsList")
    public ApiResult<Object> goodsList(@RequestBody Goods goods){

        return ApiResult.newSuccess(goodsService.goodsList(goods));
    }

    @PostMapping("/getGoodsInfo")
    @ApiOperation("商品详情")
    @Permission(permission = "admin:goods:getGoodsInfo")
    public ApiResult<Object> getGoodsInfo(@RequestBody Goods goods){
        return ApiResult.newSuccess(goodsService.getGoodsInfo(goods));
    }

}
